package Unicart.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;

public class PageManager {

  private WebDriver driver;

  public MainPage mainPage;
  public LoginPage loginPage;
  public InternalPage internalPage;
  public UserProfilePage userProfilePage;
  public RegistrationPage registrationPage;
  public ForgotPasswordPage forgotPasswordPage;
  public BasketEmptyPage basketEmptyPage;
  public BasketPage basketPage;
  public ClientDataPage clientDataPage;
  public SuccessOrderingPage successOrderingPage;
  public OrderAdminPage orderAdminPage;

  public PageManager(WebDriver driver) {
    this.driver = driver;
    mainPage = initElements(new MainPage(this));
    loginPage = initElements(new LoginPage(this));
    internalPage = initElements(new InternalPage(this));
    userProfilePage = initElements(new UserProfilePage(this));
    registrationPage = initElements(new RegistrationPage(this));
    forgotPasswordPage = initElements(new ForgotPasswordPage(this));
    basketEmptyPage = initElements(new BasketEmptyPage(this));
    basketPage = initElements(new BasketPage(this));
    clientDataPage = initElements(new ClientDataPage(this));
    successOrderingPage = initElements(new SuccessOrderingPage(this));
    orderAdminPage = initElements(new OrderAdminPage(this));
  }
  
  private <T extends Page> T initElements(T page) {
	//PageFactory.initElements(driver, page);
	//PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
	PageFactory.initElements(new DisplayedElementLocatorFactory(driver, 3), page);
    return page;
  }
  
  public WebDriver getWebDriver() {
    return driver;
  }

}
